<?php
class Admin extends MY_Controller {
	
	
	function index(){
		$data['title'] = 'Admin';
		$data['school_data'] = $this->school_data;

		$this->template->set_body(NULL, '', TRUE);
		$this->template->load_template('default', $data);
	}
	
	/*=======================Account Section Start=================================*/
	function change_password(){
		$data['title'] = 'Change Password';
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vAccountChangePassword', '', TRUE);
		$this->template->load_template('default', $data);

	}
	/*=======================Account Section End=================================*/
	
	/*=======================User Section Start=================================*/
	function add_user(){
		$data['title'] = 'Add User';
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vUserAddUser', '', TRUE);
		$this->template->load_template('default', $data);
	}
	/*=======================User Section End=================================*/
	
	/*=======================School Setting Start=================================*/
	function school_setting(){
		$data['title'] = 'School Setting';
		$data['school_data'] = $this->school_data;
		$data['school_setting'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vSchoolSetting', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function announcement(){
		$this->load->model('M_school');
		
		$data['title'] = 'Announcements';
		$data['announcements'] = $this->M_school->get_announcements();
		
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vSchoolAnnouncements', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
	}
	
	function calendar(){
		
		$this->load->model('M_school');
		$data['title'] = 'Calendar of Events';
		$data['announcements'] = $this->M_school->get_calendar_events();
		
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vSchoolCalendar', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	function school_year($message = ''){
		
		$this->load->model('M_school');
		$data['title'] = 'School year Settings';
		$data['sy_data'] = $this->M_school->get_school_year();
		$data['message'] = $message;
	
		
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vSchoolYear', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
		
	}
	
	function update_schoolyear(){
			$current_sy_id 	= $this->input->post('current_sy_id',TRUE);
			$input['sy_id']	= $this->input->post('sy_id',TRUE);
			
			$this->load->model('M_school');
			$this->form_validation->set_rules('sy_id','School year','required');
			if($this->form_validation->run() == FALSE){
					$message = '<div class="error">An error was encountered while processing request, Please Try Again</div>';
					$this->school_year($message);
			}else{
				if($this->M_school->update_current_schoolyear($current_sy_id,$input) == FALSE){
					$message = '<div class="error">An error was encountered while processing request, Please Try Again</div>';
					$this->school_year($message);
				}else{
					$message = '<div class="success">Changes Have Been Saved</div>';
					$this->school_year($message);				
				}
			}
	}
	
	function functions_schoolyear($mode='',$id = FALSE){
			$this->load->model('M_school');
			$data['title'] = $mode.' School Year';
			$data['heading'] = $mode.' School Year';
			$data['mode'] 	 = $mode;
			$data['school_data'] = $this->school_data;
		
		switch($mode)
		{
			case $mode == 'add' AND $id == FALSE:
				$this->template->set_body('page-blocks/page-module/vSchoolAddSy', $data, TRUE);
			break;
			case $mode == 'update' AND $id !== FALSE:
				$data['sy_data'] = $id !== FALSE ? $this->M_school->get_school_year($id) : NULL;
				$this->template->set_body('page-blocks/page-module/vSchoolAddSy', $data, TRUE);
			break;
			case $mode == 'del':
			$data['sy_data'] = $this->M_school->get_school_year();
				$this->template->set_body('page-blocks/page-module/vSchoolDelSy', $data, TRUE);
			break;
			case $mode == 'delete' AND $id !== FALSE:
				if($this->M_school->delete_school_year($id) == FALSE){
					$this->set_message_redirect('error','Unable to process request','admin/functions_schoolyear/del');
				}else{
					$this->set_message_redirect('success','Data was successfully deleted','admin/functions_schoolyear/del');
				}
			break;
			default:
				redirect('admin/school_year');
			break;
		}
			
		
		
		$this->template->load_template('default', $data);
	}
	
	function current_semester(){
		$this->load->model('M_course');
		
		$data['current_semester'] = $this->M_course->get_current_semester();

		$data['title'] = "Enrollment Settings";
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vSemesterCurrentSemester', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
	}
	
	
	function set_semester(){
		$this->load->model('M_course');
		if($this->M_course->set_current_semester($this->input->post('semester_id'))){
			$this->session->set_flashdata(array('type'=>'success', 'msg' =>'New semester has been successfully set.'));
			redirect('admin/current_semester');
		}
		
	}
	
	//pop up window
	function select_semester(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_semester(true);
		$data['title'] = 'Select Course';
		
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-popups/vSemesterSelectSemester', $data, FALSE);
		$this->template->load_template('default', $data);
		
	}
	/*=======================School Setting End=================================*/
	
	/*=======================Course Setting Start=================================*/
	function level(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_levels();
		$data['title'] = 'Level';
		
		$data['school_data'] = $this->school_data;
		$this->template->set_body('page-blocks/page-module/vCourseLevel', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	function add_year_level(){
		$this->load->model('M_finance');
		$data['title'] = 'Add Year Level';
		
		$data['school_data'] = $this->school_data;
		$data['fee_cat'] = $this->M_finance->get_fee_category(FALSE);
		$this->template->set_body('page-blocks/page-module/vCourseAddLevel', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
	}
	
	function edit_year_level($level_id){
		$this->load->model(array('M_course','M_finance'));
		
		$data['yr_level'] 		= $this->M_course->get_year_level($level_id);
		$data['yr_level_fees'] 	= $this->M_course->get_year_level_fees($level_id);
		$data['fee_cat'] = $this->M_finance->get_fee_category(FALSE);
		$data['title'] = 'Edit Year Level';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseEditLevel', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	function semester(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_semester();
		$data['title'] = 'Semester';
		$data['title'] = 'Edit Year Level';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseSemester', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
	}
	
	function add_semester(){
		$data['title'] = 'Add Semester';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseAddSemester', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function edit_semester($semester_id){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_semester($semester_id);
		$data['title'] = 'Edit Semester';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseEditSemester', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	
	function subject(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_subject();
		$data['title'] = 'Subjects';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseSubject', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	function add_subject(){
		$data['title'] = 'Add Subject';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseAddSubject', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function edit_subject($subject_id){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_subject($subject_id);
		$data['title'] = 'Edit Subject';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseEditSubject', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function course(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_course();
		$data['title'] = 'Course';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourse', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function add_new_course(){
		
		$data['title'] = 'Add New Course';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseAddCourse', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function edit_course($id = ''){
		$this->load->model('M_course');
		$data['db_entries'] = $this->M_course->get_course($id = $id=='' ? NULL : $id);
		
		$data['title'] = 'Edit Course';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseEditCourse', $data, TRUE);
		$this->template->load_template('default', $data);
		
		
	}
	
	/*=======================Course Setting End=================================*/
	
	/*=======================Finance Setting Start=================================*/
	function fee_category_creator(){
		$this->load->model('M_finance');
		
		$data['db_entries'] = $this->M_finance->get_fee_category();
		$data['title'] = 'Fee Category Creator';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceFeeCategoryCreator', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function fee_creator(){
		$this->load->model('M_finance');
		
		$data['db_entries'] = $this->M_finance->get_all_fee();
		$data['title'] = 'Fee Creator';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceFeeCreator', $data, TRUE);
		$this->template->load_template('default', $data);
			
	}
	
	
	function add_fee(){
		$data['title'] = 'Add Fee';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceAddFee', $data, TRUE);
		$this->template->load_template('default', $data);
	
	}
	
	function add_fee_category(){
		$data['title'] = 'Add Fee Category';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceAddFeeCategory', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function edit_fee_cat($id = FALSE){
		if($id !== FALSE){
		$this->load->model('M_finance');
		$data['title'] = 'Edit Fee Category';
		$data['fee_by_cat'] = $this->M_finance->get_fee_by_category($id);
		$data['category'] = $this->M_finance->get_fee_category($id);
		$data['get_all_fees'] = $this->M_finance->get_all_fee();
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceEditFeeCategory', $data, TRUE);
		$this->template->load_template('default', $data);

		}else{
			redirect('admin/fee_category_creator');
		}
		
	}
	
	function edit_fee($fee_id){
		$this->load->model('M_finance');
		
		$data['db_entries'] = $this->M_finance->get_fee($fee_id);
		$data['title'] = 'Edit Fee';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vFinanceEditFee', $data, TRUE);
		$this->template->load_template('default', $data);
			
	}
	

	/*=======================Finance Setting END=================================*/
	
	/*=======================Student Section START=================================*/
	
	function add_student() {
		$this->load->model('M_course');
		
		if($this->form_validation->run('add_student_admin') == FALSE){
			
		}
		else {
			
			$this->load->model('M_student');
			$v = (object) $this->input->post();
			
			
			if($this->M_student->add_student($v)){
				$session = array('type' => 'success', 'msg' => 'Student added successfully');
				$this->session->set_flashdata($session);
				redirect('admin/add_student');
				
			}
			
		}
		$data['title'] = 'Add Student';
		$data['db_entries'] = $this->M_course->get_all_levels();
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vStudentAddStudent', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	//pop up window
	function select_course(){
		$this->load->model('M_course');
		
		$data['db_entries'] = $this->M_course->get_all_course();
		$data['title'] = 'Select Course';
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-popups/vCourseSelectCourse', $data, FALSE);
		$this->template->load_template('default', $data);
	
	}
/*  =============================  update student data  start ======================================== */	
	function update_student_data($id='', $cancel = FALSE, $system_message = ''){
		
		if($cancel == md5(strtolower('cancel'))){
			$this->session->set_userdata('checkbox_checked',FALSE);
		}
		$data['system_message'] = $system_message;
		$data['title'] = 'Edit Student Profile';
		$this->load->helper('data_format');
		$this->load->model('M_course');
		$this->load->model('M_student');
		
		$data['db_entries'] = $this->M_student->get_profile($id);
		foreach($data['db_entries'] as $db_entry){
			$id_no = $db_entry->id_no;	
		}
		
		$data['db_entries2'] = $this->M_course->get_approved_subjects($id_no);
		$data['school_data'] = $this->school_data;
		
		
		$this->template->set_body('page-blocks/page-module/vStudentEditProfile', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	public function post_edit_student_profile(){

		$user_id = $this->input->post('user_id',TRUE);
		$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
		// Form validation rules can be found in config/form_validation
		if($this->form_validation->run('update_student_data') === FALSE){
			$message = '<div class="error">Some fields have incorrect values</div>';
			$this->session->set_userdata('checkbox_checked',TRUE);
			$this->profile($user_id,'',$message);
		}else{
			$this->load->model('M_student');
			
			$user_d = $this->input->post('user_id',TRUE);
			$input['lastname'] = $this->input->post('lastname',TRUE);
			$input['firstname'] = $this->input->post('firstname',TRUE);
			$input['middlename'] = $this->input->post('middlename',TRUE);
			$input['gender'] = $this->input->post('gender',TRUE);
			$input['civilstatus'] = $this->input->post('civilstatus',TRUE);
			$input['dob'] = $this->input->post('dob',TRUE);
			$input['pob'] = $this->input->post('pob',TRUE);
			$input['age'] = $this->input->post('age',TRUE);
			$input['disability'] = $this->input->post('disability',TRUE);
			$input['nationality'] = $this->input->post('nationality',TRUE);
			$input['religion'] = $this->input->post('religion',TRUE);
			$input['contactnumber'] = $this->input->post('contactnumber',TRUE);
			$input['email'] = $this->input->post('email',TRUE);
			$input['presentaddress'] = $this->input->post('presentaddress',TRUE);
			$input['fathername'] = $this->input->post('fathername',TRUE);
			$input['fatheroccupation'] = $this->input->post('fatheroccupation',TRUE);
			$input['fathercontact'] = $this->input->post('fathercontact',TRUE);
			$input['mothername'] = $this->input->post('mothername',TRUE);
			$input['motheroccupation'] = $this->input->post('motheroccupation',TRUE);
			$input['mothercontact'] = $this->input->post('mothercontact',TRUE);
			$input['parentaddress'] = $this->input->post('parentaddress',TRUE);
			$input['guardianname'] = $this->input->post('guardianname',TRUE);
			$input['guardiancontact'] = $this->input->post('guardiancontact',TRUE);
			$input['guardianaddress'] = $this->input->post('guardianaddress',TRUE);
			$input['eschoolname'] = $this->input->post('eschoolname',TRUE);
			$input['eschooladdress'] = $this->input->post('eschooladdress',TRUE);
			$input['eyeargraduate'] = $this->input->post('eyeargraduate',TRUE);
			$input['sschoolname'] = $this->input->post('sschoolname',TRUE);
			$input['sschooladdress'] = $this->input->post('sschooladdress',TRUE);
			$input['syeargraduate'] = $this->input->post('syeargraduate',TRUE);
			$input['vschoolname'] = $this->input->post('vschoolname',TRUE);
			$input['vschooladdress'] = $this->input->post('vschooladdress',TRUE);
			$input['vyeargraduate'] = $this->input->post('vyeargraduate',TRUE);
			$input['tschoolname'] = $this->input->post('tschoolname',TRUE);
			$input['tschooladdress'] = $this->input->post('tschooladdress',TRUE);
			$input['tyeargraduate'] = $this->input->post('tyeargraduate',TRUE);
			$input['oschoolname'] = $this->input->post('oschoolname',TRUE);
			$input['oschooladdress'] = $this->input->post('oschooladdress',TRUE);
			$input['oyeargraduate'] = $this->input->post('oyeargraduate',TRUE);
			$input['updated'] =  date('Y-m-d H:i ');
			

			if($this->M_student->update_stud_profile($input,$user_id) == FALSE){
				$message = '<div class="error">An erro was encountered while updating data</div>';
				$this->update_student_data($user_id,FALSE,$message);
			}else{
				$success = array(
					'type' => 'success',
					'msg' => 'update was successfull'
				);
				$this->session->set_userdata('checkbox_checked',FALSE);
				$message = '<div class="success">Update Saved</div>';
				$this->update_student_data($user_id,FALSE,$message);
			}
		}
	}	
/*  =============================  update student data  end======================================== */		
	function search_student(){
		$this->load->model('M_search');
		if($this->session->flashdata('search_stud') == 'TRUE'){
			$input['firstname']  = $this->session->flashdata('search_stud_firstname');
			$input['lastname'] 	 = $this->session->flashdata('search_stud_lastname');
			$input['middlename'] = $this->session->flashdata('search_stud_middlename');
			$input['id_no'] 	= $this->session->flashdata('search_stud_id_no');
			$input['course_id'] = $this->session->flashdata('search_stud_course_id');
			$data['db_entries'] = $this->M_search->get_student($input);
		}else{
			$input = FALSE;
		}
		
		$data['title'] = "Search Students";
		
		$data['course_menu'] = $this->M_search->get_course_menu();	
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vSearchStudents', $data, TRUE);
		$this->template->load_template('default', $data);

		
	}
	/*=======================Student Section END=================================*/
	

	
	/*=======================Enrollment Section Start=================================*/
	function pending_enrollees(){
		$this->load->model('M_student');
		$data['db_entries'] = $this->M_student->get_all_pending_enrollees();
		
		$data['title'] = "Search Students";
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vEnrollmentPendingEnrollees', $data, TRUE);
		$this->template->load_template('default', $data);
		
	
	}
	
	function view_enrollee(){
		$id_no = $this->uri->segment(3, FALSE);	
		$this->load->Model('M_student');
		$this->load->Model('M_course');
		
		$data['title'] = 'View enrollee';
		$data['profile'] = $this->M_student->get_enrollee($id_no);
		$data['school_data'] = $this->school_data;
		
		if($this->M_student->get_student_status($id_no)->enrollmentstatus == 'pending'){
			$data['db_entries'] = $this->M_course->get_selected_subjects($id_no, TRUE);
			$data['db_entries2'] = $this->M_course->get_approved_subjects($id_no);

		}
		
		$this->template->set_body('page-blocks/page-module/vEnrollmentViewEnrollee', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	
	
	function approve_subjects(){
		$id_no = $this->input->post('id_no');
		$subjects = $this->input->post('selectedsubjects');	
		
		$this->load->model('M_student');
		$this->load->model('M_course');
		
		$this->M_course->approve_subjects($id_no, $subjects);		
		
		redirect('admin/view_enrollee/'.$id_no);
	}
	
	function approve_student(){
		$this->load->model('M_student');
		$id_no = $this->input->post('id_no');
		if($this->M_student->verify_student($id_no))
			redirect('admin/view_enrollee/'.$id_no);
	}
	
	function cancel_approvement(){
		$id_no = $this->input->post('id_no');
		$subjects = $this->input->post('selectedsubjects');	
		$this->load->model('M_course');
		
		$this->M_course->cancel_approvement($subjects, $id_no);
		redirect('admin/view_enrollee/'.$id_no);	
		
	}
	/*=======================Enrollment Section ENd=================================*/
/*=======================Assign subjects to course and year=================================*/
	
	function sucl()
	{
		$this->load->model('M_course');
		$data['school_data'] = $this->school_data;
		$data['title'] = 'Add subjects to course and level';
		$data['courses'] = $this->M_course->get_all_course();
		$data['yr_level'] = $this->M_course->get_all_levels();
				
		$this->template->set_body('page-blocks/page-module/vCourseSucl', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function show_sucl()
	{
		$this->load->model('M_course');
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vCourseShowSucl', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	/*=======================Assign subjects to course and year end=================================*/
	
	/*=======================User Section START=================================*/
	
	function search_user()
	{
		$this->load->model('M_search');
		if($this->session->flashdata('search_user') == TRUE){
			$input['username'] = $this->session->flashdata('search_user_username');
			$input['usertype'] = $this->session->flashdata('search_user_usertype');
			$data['db_entries'] = $this->M_search->get_user($input);
		}else{
			$input = FALSE;
		}
		
		$data['title'] = "Search Users";
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vSearchUsers', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	
	/*=======================User Section END=================================*/
	
	/*=======================Room Section START=================================*/
	
	function manage_rooms()
	{
		$this->load->model('M_rooms');
		$data['db_entries'] = $this->M_rooms->get_all_rooms();
		
		$data['title'] = "Manage Rooms";
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vRoomsManageRooms', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	
	function add_room(){
		$data['title'] = "Add Room";
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vRoomsAddRoom', $data, TRUE);
		$this->template->load_template('default', $data);
	}
	
	function post_add_room(){
		$this->form_validation->set_rules('code', 'Room Code', 'required');
		$this->form_validation->set_rules('description', 'Description', 'required');
		
		if($this->form_validation->run() == FALSE){
			$this->set_message_redirect('error', 'Please fill up all the fields', 'admin/add_room');
		}
		else {
			
			$this->load->model('M_rooms');
			if($this->M_rooms->add_room((object) $this->input->post()))
				$this->set_message_redirect('success', 'Room added successfully', 'admin/add_room');
			else 
				$this->set_message_redirect('error', 'Something went wrong please try again', 'admin/add_room');
			
		}
	}
	
	
	function edit_room(){
		$room_id = $this->uri->segment(3);
		
		$this->load->model('M_rooms');
		$data['db_entries'] = $this->M_rooms->get_room($room_id);
		$data['title'] = "View Room";
		$data['school_data'] = $this->school_data;
		
		$this->template->set_body('page-blocks/page-module/vRoomsEditRoom', $data, TRUE);
		$this->template->load_template('default', $data);
		
	}
	
	function post_edit_room(){
		$this->form_validation->set_rules('code', 'Code', 'required');
		$this->form_validation->set_rules('name', 'Room Name', 'required');
		
		if($this->form_validation->run() == FALSE){
			$this->set_message_redirect('error', validation_errors(), 'admin/edit_room/'.$this->input->post('room_id'));
		}
		else {
			
			$this->load->model('M_rooms');
			if($this->M_rooms->edit_room((object) $this->input->post()))
				$this->set_message_redirect('success', 'Room edited successfully', 'admin/edit_room/'.$this->input->post('room_id'));
			else 
				$this->set_message_redirect('error', 'Something went wrong please try again', 'admin/edit_room/'.$this->input->post('room_id'));
			
		}
	}
	
	function delete_room(){
		$this->load->model('M_rooms');
		if($this->M_rooms->delete_room($this->uri->segment(3))){
			$this->set_message_redirect('success', 'Room deleted successfully', 'admin/manage_rooms');	
		}
		
	}
	/*=======================Room Section END=================================*/
	
		private function set_message_redirect($type, $msg, $location){
			$data = array(
				'type' => $type,
				'msg' => $msg
			);
			$this->session->set_flashdata($data);
			redirect($location);
		}
	
}

?>